<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of mtimes</title>
  <meta name="keywords" content="mtimes">
  <meta name="description" content="C = A*B">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="#">tt2</a> &gt; <a href="index.html">@tt_tensor</a> &gt; mtimes.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for tt2/@tt_tensor&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>mtimes
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>C = A*B</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [c] = mtimes(a,b) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">   C = A*B
   [C]=MTIMES(A,B)
   TT-Tensor-by-Matrix multiplication

   Either A or B may be a TT-tensor. The rest argument must be a matrix
   with sizes consistent to the respective &quot;tail&quot; rank of a tensor (or a
   scalar).</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>	Mode sizes of the TT-matrix</li><li><a href="reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>	Reshape of the TT-tensor</li><li><a href="size.html" class="code" title="function [sz] = size(tt,dim)">size</a>	Mode sizes of the TT-tensor</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [c] = mtimes(a,b)</a>
0002 <span class="comment">%   C = A*B</span>
0003 <span class="comment">%   [C]=MTIMES(A,B)</span>
0004 <span class="comment">%   TT-Tensor-by-Matrix multiplication</span>
0005 <span class="comment">%</span>
0006 <span class="comment">%   Either A or B may be a TT-tensor. The rest argument must be a matrix</span>
0007 <span class="comment">%   with sizes consistent to the respective &quot;tail&quot; rank of a tensor (or a</span>
0008 <span class="comment">%   scalar).</span>
0009 
0010 <span class="keyword">if</span> isa(a,<span class="string">'double'</span>) &amp;&amp; isa(b,<span class="string">'tt_tensor'</span>)
0011     d = b.d;
0012     cr1 = b.core(b.ps(1):b.ps(2)-1);
0013     cr1 = <a href="reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(cr1, b.r(1), b.n(1)*b.r(2));
0014     <span class="keyword">if</span> (numel(a)==1) 
0015         rnew = b.r(1);
0016     <span class="keyword">else</span>
0017         rnew = <a href="size.html" class="code" title="function [sz] = size(tt,dim)">size</a>(a,1);
0018     <span class="keyword">end</span>;
0019     dps = rnew*b.n(1)*b.r(2) - b.r(1)*b.n(1)*b.r(2);
0020     cr1 = a*cr1;
0021     
0022     c = b;
0023     c.core=c.core(b.ps(2):b.ps(d+1)-1);
0024     c.core = [cr1(:); c.core(:)];
0025     c.ps(2:d+1)=b.ps(2:d+1)+dps;
0026     c.r(1) = rnew;
0027     
0028 <span class="comment">%     c=b;</span>
0029 <span class="comment">%     crc=c.core;</span>
0030 <span class="comment">%     if (size(crc,2) == 1 )</span>
0031 <span class="comment">%       crc=crc.';</span>
0032 <span class="comment">%     end</span>
0033 <span class="comment">%     ps=c.ps;</span>
0034 <span class="comment">%     r=c.r;</span>
0035 <span class="comment">%     n=c.n;</span>
0036 <span class="comment">%     mm=crc(ps(1):ps(2)-1);</span>
0037 <span class="comment">%     mm=reshape(mm,[r(1),n(1)*r(2)]);</span>
0038 <span class="comment">%     mm=a*mm;</span>
0039 <span class="comment">%     crc(ps(1):ps(2)-1)=[];</span>
0040 <span class="comment">%     crc=[mm(:)',crc];</span>
0041 <span class="comment">%     r(1)=size(a,1);</span>
0042 <span class="comment">%     ps=ps-ps(2)+1+r(1)*n(2)*r(2);</span>
0043 <span class="comment">%     ps(1)=1;</span>
0044 <span class="comment">%     c.ps=ps;</span>
0045 <span class="comment">%     c.core=crc;</span>
0046 <span class="comment">%     c.r=r;</span>
0047 <span class="keyword">elseif</span> isa(a,<span class="string">'tt_tensor'</span>) &amp;&amp; isa(b,<span class="string">'double'</span>) 
0048     d = a.d;
0049     crd = a.core(a.ps(d):a.ps(d+1)-1);
0050     crd = <a href="reshape.html" class="code" title="function [tt2]=reshape(tt1,sz,eps, rl, rr)">reshape</a>(crd, a.r(d)*a.n(d), a.r(d+1));
0051     <span class="keyword">if</span> (numel(b)==1) 
0052         rnew = a.r(d+1);
0053     <span class="keyword">else</span>
0054         rnew = <a href="size.html" class="code" title="function [sz] = size(tt,dim)">size</a>(b,2);
0055     <span class="keyword">end</span>;    
0056     ps_new = a.ps(d) + a.r(d)*a.n(d)*rnew;
0057     crd = crd*b;
0058     
0059     c = a;
0060     c.core(a.ps(d):ps_new-1)=crd(:);
0061     c.core = c.core(1:ps_new-1);
0062     c.ps(d+1)=ps_new;
0063     c.r(d+1) = rnew;
0064     
0065 <span class="keyword">else</span>
0066     error(<span class="string">'Use mtimes(full(A),full(B)).'</span>);
0067 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Wed 08-Feb-2012 18:20:24 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>